/**
 * Copyright(c) kyle.
 */
package org.example.jvm.remote_executor;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.PrintStream;

/**
 * 为Javaclass劫持java.lang.System提供支持
 * 出列out和err之外，其余的都直接转发给System
 *
 * @author kyle
 * @version 1.00.00
 * @since [2020-12-05 16:10]
 * @updateUser [Kyle]
 * @updateRemark [说明本次修改内容]
 * @date [2020-12-05 16:10]
 */
public class HackSystem {
    // @formatter:off
    public static final InputStream in = System.in;
    public static ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    public static final PrintStream out = new PrintStream(buffer);
    public static final PrintStream err = out;

    // @formatter:on
    public static String getBufferString() {
        return buffer.toString();
    }

    public static void setSecurityManager(final SecurityManager s) {
        out.println("setSecurityManager");
        System.setSecurityManager(s);
    }

    public static SecurityManager getSecurityManger() {
        return System.getSecurityManager();
    }

    public static long currentTimeMillis() {
        return System.currentTimeMillis();
    }

    public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length) {
        System.arraycopy(src, srcPos, dest, destPos, length);
    }

    public static void clearBuffer() {
        buffer.reset();
    }

    public static int identityHashCode(Object x) {
        return System.identityHashCode(x);
    }

    //接下来的方法都可以抄System
}
